package com.stn.zjx.givingtreasure.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.activity.address.EditAddressActivity;
import com.stn.zjx.givingtreasure.domain.SupportBankSpeciesDomain;
import com.stn.zjx.givingtreasure.domain.UserAddressDomain;
import com.stn.zjx.givingtreasure.net.BaseApi;
import com.vondear.rxtools.RxActivityTool;

import java.util.ArrayList;
import java.util.List;

public class SupportBankCardItemListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

   public List<SupportBankSpeciesDomain.DataBean> dataBeanList=new ArrayList<>();
   private LayoutInflater inflater;
   public Context context;

   public SupportBankCardItemListAdapter(Context context) {
       inflater = LayoutInflater.from(context);
      this.context=context;
   }

   @Override
   public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       RecyclerView.ViewHolder vh = new IndexHolder(inflater.inflate(R.layout.item_support_bank_card, parent, false));
       return vh;
   }
   @SuppressLint("SetTextI18n")
   @Override
   public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
                   IndexHolder ih= (IndexHolder) viewHolder;
       SupportBankSpeciesDomain.DataBean dataBean= dataBeanList.get(i);
          ih.name.setText(dataBean.getBankCardName());
       Glide.with(context)
               .asBitmap()
               .load(BaseApi.alipayGetBankLogo+dataBean.getBankCardEnName())
               .into(ih.iv);
   }

   @Override
   public int getItemCount() {
       return dataBeanList.size();
   }
   public void refreshList(List<SupportBankSpeciesDomain.DataBean> dataBeans) {
       dataBeanList.removeAll(dataBeanList);
       dataBeanList.addAll(dataBeans);
       notifyDataSetChanged();
   }

   public void appendList(List<SupportBankSpeciesDomain.DataBean> dataBeans) {
       dataBeanList.addAll(dataBeans);
       notifyDataSetChanged();
   }

   public void clearList() {
       dataBeanList.removeAll(this.dataBeanList);
       notifyDataSetChanged();
   }


   public  class IndexHolder extends RecyclerView.ViewHolder{

             public View rootView;
          public ImageView iv;
          public TextView name;
        IndexHolder(@NonNull View itemView) {
           super(itemView);
           rootView=itemView;
            iv=itemView.findViewById(R.id.iv);
            name=itemView.findViewById(R.id.name);
        }
   }

}